<?php

     $agent  = $_SERVER['HTTP_USER_AGENT'];
     $agentip=$_SERVER['REMOTE_ADDR']; 
     $browser = '';
     $browser_ver = '';
     $browserinfo='';
  
     if (preg_match('/OmniWeb\/(v*)([^\s|;]+)/i', $agent, $regs))
     {
         $browser = 'OmniWeb';
         $browser_ver = $regs[2]; 
     }
  
     if (preg_match('/Netscape([\d]*)\/([^\s]+)/i', $agent, $regs))
     {
         $browser = 'Netscape';
         $browser_ver = $regs[2];
     }
  
     if (preg_match('/safari\/([^\s]+)/i', $agent, $regs))
     {
         $browser = 'Safari';
         $browser_ver = $regs[1];
     }
  
     if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs))
     {
         $browser = 'Internet Explorer';
         $browser_ver = $regs[1];
     }
  
     if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs))
     {
         $browser = 'Opera';
         $browser_ver = $regs[1];
     }
  
     if (preg_match('/NetCaptor\s([^\s|;]+)/i', $agent, $regs))
     {
         $browser = '(Internet Explorer ' .$browser_ver. ') NetCaptor';
         $browser_ver = $regs[1];
     }
  
     if (preg_match('/Maxthon/i', $agent, $regs))
     {
         $browser = '(Internet Explorer ' .$browser_ver. ') Maxthon';
         $browser_ver = '';
     }
  
     if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs))
     {
         $browser = 'FireFox';
         $browser_ver= $regs[1];
     }
	 
     if (preg_match('/Chrome\/([^\s]+)/i', $agent, $regs))
     {
         $browser = 'Chrome';
         $browser_ver= $regs[1];
     }
  
     if (preg_match('/Lynx\/([^\s]+)/i', $agent, $regs))
     {
         $browser = 'Lynx';
         $browser_ver = $regs[1];
     }
  
     if ($browser != '')
     {
        $browserinfo= $browser.' '.$browser_ver;
     }
     else
     {
         $browserinfo= 'Unknow browser';
     }
   

include_once("../includes/db_conn_new.inc");

$applicant_application_loan_purpose = NULL;
$applicant_type = 'single';
$applicant_title = NULL;
$applicant_first_name  = NULL;
$applicant_middle_name  = NULL;
$applicant_sur_name  = NULL;
$applicant_residency = NULL;
$applicant_mobile = NULL;
$applicant_phone = NULL;
$applicant_email_address = NULL;
$applicant_dob = NULL;
$applicant_drivers_license = NULL;
$applicant_resedential_address = NULL;
$applicant_resendential_status = NULL;
$applicant_boardingwith_name = NULL;
$applicant_resedential_period = NULL;
$applicant_resedential_length = NULL;
$applicant_numberof_dependent = NULL;
$loan_purpose_reason = NULL;
$applicant_employment_status = NULL;
$applicant_employment_type = NULL;
$applicant_employment_occupation = NULL;
$applicant_employer_name = NULL;
$applicant_employer_phone = NULL;
$applicant_employer_name = NULL;
$applicant_income_aftertax = NULL;
$applicant_income_aftertax_period = NULL;
$applicant_income_centrelink = NULL;
$applicant_other_income = NULL;
$applicant_rental_income = NULL;
$applicant_other_income_period = NULL;
$applicant_hardship = NULL;
$applicant_gambling = NULL;
$applicant_claims = NULL;
$applicant_credit_history = NULL;
$applicant_total_outstanding = NULL;
$applicant_date_discharge = NULL;
$applicant_credit_discharge = NULL;
$default_after_discharge = NULL;  
$why_choose_mc = NULL; 
$ExistingClient=NULL;
$applicant_liabilities = NULL;
$mysql_update_current_datetime  = 'CURRENT_TIMESTAMP';
$new_app_id = NULL;
$loan_amount = NULL;
$term = NULL;

if(isset($_SESSION['app_id']))
{			
	
	 $sql = "SELECT a . *, c . *, e . *, i . *, cr . *, l . * FROM  `crm_application` a
			INNER JOIN  `crm_contact` c ON ( c.app_id = a.app_id ) 			
			INNER JOIN  `crm_employment` e ON (e.app_id = a.app_id)
			INNER JOIN  `crm_income` i ON (i.app_id = a.app_id)
			INNER JOIN  `crm_applicationcredit` cr ON (cr.app_id = a.app_id)
			INNER JOIN  `crm_liabilities` l ON (l.app_id = a.app_id)
			WHERE a.app_id = ".$_SESSION['app_id']."
			GROUP BY a.app_id;";	
			
		
	$result = mysql_query($sql);
	$num_rows = mysql_num_rows($result);
	
	
	if($num_rows > 0)
	{
		while($row = mysql_fetch_array($result))
		{
		    $loan_amount = $row['DesiredAmount'];
		    $term = $row['mc_preferred_loan_period'];
		    $applicant_application_loan_purpose = $row['PurposeSummary'];
                    $loan_purpose_reason = $row['loanpurposereason'];
                    $applicant_title = $row['Title'];
                    $applicant_first_name = $row['FirstName'];
                    $applicant_middle_name = $row['MiddleName'];
                    $applicant_sur_name = $row['SurName'];
                    $applicant_residency = $row['Citizenship'];
		    $applicant_mobile = $row['Mobile'];
                    $applicant_phone = $row['HomePhone'];
                    $applicant_email_address = $row['Email'];
		         if($row['DateBirth'] != '')
	                            $applicant_dob = date("d/m/Y", strtotime($row['DateBirth']));
                    $applicant_drivers_license = $row['DriverLicense']; 		
                    $applicant_resedential_address = $row['StreetNo'].' '.str_replace(",", " ", $row['Street']).','.$row['Suburb'].' '.$row['State'].' '.$row['PostCode'];
    		    $applicant_streetnumber=$row['StreetNo'];
		    $streetarray = explode( ',', $row['Street'] );
			if($streetarray!=NULL)
                            {
                                    $applicant_street=$streetarray[0];			
                                    $applicant_streettype=$streetarray[1];
                            }
                            else
                            {
                                    $applicant_street=$row['Street'];			
                                    $applicant_streettype=$row['Street'];
                            }
                    $applicant_suburb=$row['Suburb'];
                    $applicant_state=$row['State'];
                    $applicant_postcode=$row['PostCode'];
                    $applicant_resendential_status = $row['app_ResidentialStatus'];
                    $applicant_boardingwith_name = $row['boardingwith_name'];
                            if($row['ResidencePeriod'] == 'Month/s' && $row['ResidenceLength'] == '1')
                                    $applicant_resedential_period= '1 month';
                            else if($row['ResidencePeriod'] == 'Month/s' && $row['ResidenceLength'] == '2')
                                    $applicant_resedential_period= '2 months';
                            else if($row['ResidencePeriod'] == 'Month/s' && $row['ResidenceLength'] == '3')
                                    $applicant_resedential_period= '3 months';
                            else if($row['ResidencePeriod'] == 'Month/s' && $row['ResidenceLength'] == 'less than 1')
                                    $applicant_resedential_period= 'less than 1 month';
                            else if($row['ResidencePeriod'] == 'Month/s' && $row['ResidenceLength'] == '4 to 6')
                                    $applicant_resedential_period= '4 to 6 months';
                            else if($row['ResidencePeriod'] == 'Month/s' && $row['ResidenceLength'] == '7 to 12')
                                    $applicant_resedential_period= '7 months to 1 year';
                            else if($row['ResidencePeriod'] == 'Year/s' && $row['ResidenceLength'] == '1 to 2')
                                    $applicant_resedential_period= '1 year to 2 years';
                            else if($row['ResidencePeriod'] == 'Year/s' && $row['ResidenceLength'] == 'more than 2')
                                    $applicant_resedential_period= 'more than 2 years';

                    $applicant_numberof_dependent = $row['Dependant'];
                    $applicant_employment_status = $row['employment_status'];
                    $applicant_employment_type = $row['employment_type'];
                    $applicant_employment_occupation = $row['employment_occupation'];                    
                    $applicant_employer_phone = $row['employer_phone'];
                    $applicant_employer_name = $row['employer_name'];
                    $applicant_income_aftertax = $row['income_aftertax'];
                    $applicant_income_aftertax_period = $row['income_aftertax_period'];
                    $applicant_income_centrelink = $row['income_centrelink'];
                    $applicant_other_income = $row['income_other'];
                    $applicant_rental_income = $row['income_rental'];
		    $applicant_other_income_period = $row['income_other_period'];
                    $applicant_hardship = $row['credit_hardship'];
                    $applicant_gambling = $row['credit_gambling'];
                    $applicant_claims = $row['credit_claims'];
                    $applicant_credit_history = $row['credit_history'];
                    $applicant_total_outstanding = $row['credit_outstanding'];
                    $applicant_date_discharge=$row['credit_dischargedate'];
                    $default_after_discharge=$row['credit_discharge'];
                    $why_choose_mc=$row['WhyChooseMF'];
                    $ExistingClient=$row['ExistingClient'];
                    $liabilities_loanrepayment_payment = $row['liabilities_loanrepayment_payment'];
                    $liabilities_loanrepayment_paymentperiod = $row['liabilities_loanrepayment_paymentperiod'];
                    $liabilities_creditcard_payment = $row['liabilities_creditcard_payment'];
                    $liabilities_creditcard_paymentperiod = $row['liabilities_creditcard_paymentperiod'];
                    $liabilities_boardingrentingfee_payment = $row['liabilities_boardingrentingfee_payment'];
                    $liabilities_boardingrentingfee_paymentperiod = $row['liabilities_boardingrentingfee_paymentperiod'];
                    $liabilities_livingexpenses_payment = $row['liabilities_livingexpenses_payment'];
                    $liabilities_livingexpenses_paymentperiod = $row['liabilities_livingexpenses_paymentperiod'];
		}
	}
}
else
{
    header('Location:index.php?login');
}
$liablity_tag = array('BoardingRentingFee', 'LivingExpensesPaymen', 'PersonalLoan', 'CreditCard', 'PaydayLoan');

$arr_prefix = array('Mr','Ms','Miss','Mrs','Dr','Other');

$arr_residency = array('Australian - Born in Australia',
                        'Australian - Born overseas',
                        'Permanent Resident (PR)',
                        'New Zealand Citizen & Australian PR',
                        'Working Visa (457)',
                        'Others');

$arr_residence_status = array('I own my home outright','I have a mortgage','boarding','renting');

$arr_residence_time_at_address = array('less than 1 month', 
                                        '1 month', '2 months', 
                                        '3 months', 
                                        '4 to 6 months', 
                                        '7 months to 1 year', 
                                        '1 year to 2 years', 
                                        'more than 2 years');

$arr_loan_purpose = array('Personal bill/car rego renew',
                            'Personal purchases',
                            'Rental bond',
                            'Residential property renovation',
                            'Holiday/Wedding',
                            'Business related purpose',
                            'Other personal use');

$arr_employment_type = array('Employee', 
                                'CentrelinkAndWorkincome', 
                                'Centrelink', 
                                'Self-Employed', 
                                'Company Director', 
                                'Contractor', 
                                'Cash Income',
                                'Others');

$arr_employment_status = array('F/T', 'P/T', 'Casual', 'Temp');

$arr_period = array('Weekly', 'Fortnightly', 'Monthly');

$arr_otherincome_specify = array('2nd Job(Payslip)', 
                                    'Parent income', 
                                    'Spouse income',
                                    'Rental income', 
                                    'Interest income', 
                                    'Child Support(Court order)',
                                    'Child Support(Private)',
                                    'Private arrangement');

$arr_credit_history = array('Clean (no default)', 
							'1 default', 
							'2 defaults',
							'3 or more defaults', 
							'Under bankruptcy', 
							'Ex-bankrupt', 
							'Under Part IX debt agreement', 
							'Past Part IX debt agreement');
$ch_default_data = array('1 default', 
                '2 defaults',
                '3 or more defaults', 
                );
$ch_xbankrupt_data = array('Ex-bankrupt', 
							'Under Part IX debt agreement', 
							'Past Part IX debt agreement');
										                
?>

<script>
$( document ).ready(function() {
	
	$('#FirstName1').prop('readonly',true);
	$('#MiddleName1').prop('readonly',true);
	$('#Surname1').prop('readonly',true);
	$('#DateOfBirth1').prop('readonly','true');
	$('#Title2').attr('disabled', 'true');
	$('#Residency2').attr('disabled', 'true'); 
	
});
</script>
<script src="../assets/js/jquery.multiselect.js" type="text/javascript"></script> 
<script type="text/javascript" src="../assets/js/jquery.bgiframe.js"></script>
<script type="text/javascript" src="../assets/js/jquery.blockUI.js"></script>
<script src="../assets/js/jquery.mask.min.js" type="text/javascript"></script>  
<script type="text/javascript" src="../assets/js/date.js"></script>
<script src="../assets/js/jquery.lat.validate.js" type="text/javascript"></script>
<script src="jquery.ui.touch-punch.min.js"></script>

<script type="text/javascript" src="../assets/js/cost.js"></script>

<script type="text/javascript">
 
  $(function() {
	$('#ResidentialAddress2').autocomplete({
				source: "../includes/addressify.php",
				minLength: 3, 
				select: function (event, obj) {
				$.getJSON('../includes/getParsedAddress.php?term='+ obj.item.value, function(data) {	
			$('#ResidentialAddress2').val(data.StreetLine+', '+data.Suburb+' '+data.State+' '+data.Postcode);
			$('#Suburb1').val(data.Suburb);
			$('#State1').val(data.State);
			//$('#Postcode1').val(data.Postcode);
			$('#Number1').val(data.Number);
			$('#Street1').val(data.Street);
			$('#StreetType1').val(data.StreetType);
			$('#addressicon').show();
		});
				}
	 });
	 	<a href="login.php">login.php</a>
  });
  
    $(function() {
  <?php
	if($loan_amount == 500){
		?>
		$("#loan-range .ui-slider-range").css('width','0');
		$("#loan-range .ui-state-default").css('left','0');
		$("#LoanAmount").val(500);
		<?php
	}elseif($loan_amount == 600){
		?>
		$("#loan-range .ui-slider-range").css('width','6.7777%');
		$("#loan-range .ui-state-default").css('left','6.7777%');
		$("#LoanAmount").val(600);
		<?php
	}elseif($loan_amount == 700){
		?>
		$("#loan-range .ui-slider-range").css('width','13.3333%');
		$("#loan-range .ui-state-default").css('left','13.3333%');
		$("#LoanAmount").val(700);
		<?php
	}elseif($loan_amount == 800){
		?>
		$("#loan-range .ui-slider-range").css('width','20%');
		$("#loan-range .ui-state-default").css('left','20%');
		$("#LoanAmount").val(800);
		<?php
	}elseif($loan_amount == 900){
		?>
		$("#loan-range .ui-slider-range").css('width','26.6667%');
		$("#loan-range .ui-state-default").css('left','26.6667%');
		$("#LoanAmount").val(900);
		<?php
	}elseif($loan_amount == 1000){
		?>
		$("#loan-range .ui-slider-range").css('width','33.3333%');
		$("#loan-range .ui-state-default").css('left','33.3333%');
		$("#LoanAmount").val(1000);
		<?php
	}elseif($loan_amount == 1100){
		?>
		$("#loan-range .ui-slider-range").css('width','40%');
		$("#loan-range .ui-state-default").css('left','40%');
		$("#LoanAmount").val(1100);
		<?php
	}elseif($loan_amount == 1200){
		?>
		$("#loan-range .ui-slider-range").css('width','46.6667%');
		$("#loan-range .ui-state-default").css('left','46.6667%');
		$("#LoanAmount").val(1200);
		<?php
	}elseif($loan_amount == 1300){
		?>
		$("#loan-range .ui-slider-range").css('width','53.3333%');
		$("#loan-range .ui-state-default").css('left','53.3333%');
		$("#LoanAmount").val(1300);
		<?php
	}elseif($loan_amount == 1400){
		?>
		$("#loan-range .ui-slider-range").css('width','60%');
		$("#loan-range .ui-state-default").css('left','60%');
		$("#LoanAmount").val(1400);
		<?php
	}elseif($loan_amount == 1500){
		?>
		$("#loan-range .ui-slider-range").css('width','66.6667%');
		$("#loan-range .ui-state-default").css('left','66.6667%');
		$("#LoanAmount").val(1500);
		<?php
	}elseif($loan_amount == 1600){
		?>
		$("#loan-range .ui-slider-range").css('width','73.3333%');
		$("#loan-range .ui-state-default").css('left','73.3333%');
		$("#LoanAmount").val(1600);
		<?php
	}elseif($loan_amount == 1700){
		?>
		$("#loan-range .ui-slider-range").css('width','80%');
		$("#loan-range .ui-state-default").css('left','80%');
		$("#LoanAmount").val(1700);
		<?php
	}elseif($loan_amount == 1800){
		?>
		$("#loan-range .ui-slider-range").css('width','86.6667%');
		$("#loan-range .ui-state-default").css('left','86.6667%');
		$("#LoanAmount").val(1800);
		<?php
	}elseif($loan_amount == 1900){
		?>
		$("#loan-range .ui-slider-range").css('width','93.3333%');
		$("#loan-range .ui-state-default").css('left','93.3333%');
		$("#LoanAmount").val(1900);
		<?php
	}elseif($loan_amount == 2000){
		?>
		$("#loan-range .ui-slider-range").css('width','100%');
		$("#loan-range .ui-state-default").css('left','100%');
		$("#LoanAmount").val(2000);
		<?php
	}
	?>
	$(".well .span2 #amount").val('<?php echo $loan_amount;?>');
	});
	
	$(function() {
  <?php
	if($term == 6){
		?>
		$("#term-range .ui-slider-range").css('width','0%');
		$("#term-range .ui-state-default").css('left','0%');
		$("#due_month").val(6);<?php
	}elseif($term == 7){
		?>
		$("#term-range .ui-slider-range").css('width','16.6667%');
		$("#term-range .ui-state-default").css('left','16.6667%');
		$("#due_month").val(7);<?php
	}elseif($term == 8){
		?>
		$("#term-range .ui-slider-range").css('width','33.3333%');
		$("#term-range .ui-state-default").css('left','33.3333%');
		$("#due_month").val(8);<?php
	}elseif($term == 9){
		?>
		$("#term-range .ui-slider-range").css('width','50%');
		$("#term-range .ui-state-default").css('left','50%');
		$("#due_month").val(9);<?php
	}elseif($term == 10){
		?>
		$("#term-range .ui-slider-range").css('width','66.6667%');
		$("#term-range .ui-state-default").css('left','66.6667%');
		$("#due_month").val(10);<?php
	}elseif($term == 11){
		?>
		$("#term-range .ui-slider-range").css('width','83.3333%');
		$("#term-range .ui-state-default").css('left','83.3333%');
		$("#due_month").val(11);<?php
	}elseif($term == 12){
		?>
		$("#term-range .ui-slider-range").css('width','100%');
		$("#term-range .ui-state-default").css('left','100%');
		$("#due_month").val(12);
		<?php
	}
	?>
	
	$(".well .span2 #term").val('<?php echo $term;?>');
	});
  
  </script>
  

<!--<script src="../assets/js/jquery.form.wizard.js" type="text/javascript"></script>
 <script src="../assets/js/customfunctions_new.js" type="text/javascript"></script>-->
  
<h2><img src="../assets/css/images/bullet-form.png" />Start Your Application</h2>
<form action="requestmoneyinsert.php" method="post" id="formApp" class="formapp"> 
<fieldset class="step" id="generalDetails"> 
<div class="well">
    <div class="row-fluid">
        <div class="row-fluid">
        <p><strong> How much cash would you like?</strong> </p>
        <div class="wrap rounded">
                <strong>$300</strong><span>$2000</span>
                <div id="loan-range">
                <p>&nbsp;</p>
              <input class="hidden" id="amount"  type="text" value="" readonly/>
            </div>
                
        </div>
    </div>
    </div>
    <br><br>                                
    <div class="row-fluid">
        <p><strong> How long do you want the loan for?</strong> </p>
        <div class="wrap rounded">
                <strong>1 Month</strong><span>6 Month</span>
           <div id="term-range"><p>&nbsp;</p>
                   <input class="hidden" id="term"  type="text" readonly/>
                </div>
         </div>
    </div><br>
<br>
<br>
     <div class="row-fluid">
      <div class="span10 text-right"><br />
     <strong> Weekly Repayment</strong>
      </div> 
     <div class="span2 text-right">
      <div class="input-prepend">
            <span class="add-on">$</span>
            <input id="weekly_repayment" size="3"  value="32" class="span8" type="text" readonly="readonly"/>
            </div>
   
     </div>
     </div>
      <input type="hidden" name="LoanAmount" id="LoanAmount" value="<?php echo $loan_amount; ?>" />
     <input type="hidden" name="due_month" id="due_month" value="<?php echo $term; ?>" />
     <input type="hidden" name="browser" id="browser" value="<?php echo $browserinfo; ?>" />
     <input type="hidden" name="ipaddress" id="ipaddress" value="<?php echo $agentip; ?>" />

</div>

<h2><img src="../assets/css/images/bullet-form.png" />Personal Information</h2>
<div id="personal">
<div class="row-fluid">
    <div class="span6 control-group">
      
      <label>Title</label>
     <select name="Title2" class="required" id="Title2" <?php if(!empty($applicant_title)){ echo 'disabled=disabled'; }; ?> />
                   <option value="">-Select-</option>
                <?php 
                        foreach($arr_prefix as $title): 
                            if($title == $applicant_title):
                                echo '<option value="'.$title.'" selected="selected">'.$title.'</option>';
                            else:
                                echo '<option value="'.$title.'">'.$title.'</option>';
                            endif;
                        endforeach; 
                         ?>
                  </select>
    </div>
    <div class="span6 control-group">
        <label>First Name <span class="text-error">*</span> <a href="#" data-toggle="tooltip" title="As it appears on your driver's licence"><i class="fa fa-info-circle"></i>  </a></label>
        <input  type="text" class="required capitalize" name="FirstName1" id="FirstName1" value="<?php if(isset($applicant_first_name)) echo $applicant_first_name; ?>">
    </div>
    </div>
    <div class="row-fluid">
    <div class="span6 control-group">
        <label>Middle Name</label>
        <input  type="text" name="MiddleName1" id="MiddleName1" class="capitalize" value="<?php if(isset($applicant_middle_name)) echo $applicant_middle_name; ?>">
    </div>
    <div class="span6 control-group">
         <label>Surname <span class="text-error">*</span> <a href="#" data-toggle="tooltip" title="As it appears on your driver's licence"><i class="fa fa-info-circle"></i>  </a></label>
        <input type="text" class="required capitalize" name="Surname1" id="Surname1" value="<?php if(isset($applicant_sur_name)) echo $applicant_sur_name; ?>" >
    </div>
</div>

<div class="row-fluid"> 
    <div class="span6 control-group ">
         <label>Citizenship  <span class="text-error">*</span></label>
        <select name="Residency2" id="Residency2" class="required norm" <?php if(!empty($applicant_residency)){ echo 'disabled=disabled'; }; ?> ><option value="" disabled="disabled">-Select-</option>
                <?php 
                        foreach($arr_residency as $residency): 
                            if($residency == $applicant_residency):
                                echo '<option value="'.$residency.'" selected="selected">'.$residency.'</option>';
                            else:
                                echo '<option value="'.$residency.'">'.$residency.'</option>';
                            endif;
                        endforeach; 
                         ?>
        </select>
    </div>
    <div class="span6 control-group">
        <label>Date of Birth <span class="text-error">*</span></label>
        <input name="DateOfBirth1" type="text" class="dateOfBirth required " id="DateOfBirth1" value="<?php if(isset($applicant_dob)) echo $applicant_dob; ?>" size="10" >
    </div>
</div>
</div>
<h2><img src="../assets/css/images/bullet-form.png" />Contact Information</h2>
<div class="row-fluid">
    <div class="span6 control-group ">
         <label>Home Address <span class="text-error">*</span></label>
        <input type="text" name="ResidentialAddress2" id="ResidentialAddress2" value="<?php if(isset($applicant_resedential_address)) echo $applicant_resedential_address; ?>" class="required capitalize" placeholder="e.g. 8 George St, Sydney NSW 2220" >
    </div>
    <div class="span6 control-group ">
        <label>Residential Status <span class="text-error">*</span> </label>
        <select name="ResidentialStatus1" id="ResidentialStatus1" class="required norm" > 
        <option value="">-Select-</option>
                <?php 
                      foreach($arr_residence_status as $residency_status): 
                          if($residency_status == $applicant_resendential_status):
                              echo '<option value="'.$residency_status.'" selected="selected">'.$residency_status.'</option>';
                          else:
                              echo '<option value="'.$residency_status.'">'.$residency_status.'</option>';
                          endif;
                      endforeach; 
                       ?>
        </select>
     </div>
     <div id="addressicon">
    <div class="row-fluid">
        <div class="span6">
           
                <label>Street Number <span class="text-error">*</span></label>
                <input type="text" name="Number1" id="Number1" value="<?php if(isset($applicant_streetnumber)) 
                echo $applicant_streetnumber; ?>" class="required" />
           
        </div>
        <div class="span6">
                <label>Street <span class="text-error">*</span> </label>
                <input type="text" name="Street1" id="Street1" value="<?php if(isset($applicant_street)) 
                echo $applicant_street; ?>" class="required" />
        </div>
    </div><br/>
    
    <div class="row-fluid">
        <div class="span6 control-group ">
                <label>Street Type<a href="#" data-toggle="tooltip" title="(LINE,RD)"><i class="fa fa-info-circle"></i>  </a>
                <span class="text-error">*</span></label>
                <input type="text" name="StreetType1" id="StreetType1" class="required"  
                onblur="nameMerge(this.id)" value="<?php if(isset($applicant_streettype)) echo $applicant_streettype; ?>" />
        </div>
        <div class="span6 control-group ">
                <label>Suburb <span class="text-error">*</span></label>
                <input type="text" name="Suburb1" id="Suburb1" value="<?php if(isset($applicant_suburb))
                 echo $applicant_suburb; ?>" class="required" />
        </div>
    </div>
    
    <div class="row-fluid">
        <div class="span6 control-group ">
                <label>State <span class="text-error">*</span></label>
                <input type="text" name="State1" id="State1" value="<?php if(isset($applicant_state)) echo $applicant_state; ?>" 
                class="required" />
        </div>
        <div class="span6 control-group">
                <label>Postcode <span class="text-error">*</span></label>
                <input type="text" name="Postcode1" id="Postcode1" maxlength="4" value="<?php if(isset($applicant_postcode)) 
                echo $applicant_postcode; ?>" class="Postcode required" />
        </div>
    </div>
</div>
     </div>
     <div class="row-fluid">
    <div class="span6 control-group ">
        <label>Time at Address   </label>
        <select name="LengthOfResidenceYear1" id="LengthOfResidenceYear1" class="required ui-wizard-content">
        <option value="">Select...</option>
                <?php 
				
                foreach($arr_residence_time_at_address as $residency_year): 
                    if($residency_year == $applicant_resedential_period):
                        echo '<option value="'.$residency_year.'" selected="selected">'.$residency_year.'</option>';
                    else:
                        echo '<option value="'.$residency_year.'">'.$residency_year.'</option>';
                    endif;
                endforeach; 
                ?>
              </select>
    </div>
    <div class="span6 control-group">
        <label>Mobile Phone <a href="#" data-toggle="tooltip" title="eg:0400 000 000"><i class="fa fa-info-circle"></i>  </a>  </label>
        <input  type="text" name="Mobile1" class="required Mobile" id="Mobile1" maxlength="12" title="0400 000 000" value="<?php if(isset($applicant_mobile)) echo $applicant_mobile; ?>" >
    </div>
</div>

    
<div class="row-fluid">
    <div class="span6 control-group ">
        <label>Home Phone </label>
        <input type="text" name="Phone1" id="Phone1" class="required phly Phone" value="<?php if(isset($applicant_phone)) echo $applicant_phone; ?>"  placeholder="e.g. 09 2579 1130" />
    </div>
    <div class="span6 control-group ">
        <label>Email <a href="#" data-toggle="tooltip" title="Email is crucial for communication during the application process. "><i class="fa fa-info-circle"></i>  </a> </label>
        <input type="text" name="EMailAddress1" id="EMailAddress1"  value="<?php if(isset($applicant_email_address)) echo $applicant_email_address; ?>" placeholder="e.g. email@example.com" class="phly">
    </div>
</div>

<div class="row-fluid">
    <div class="span6 control-group ">
        <label>Loan Purpose <span class="text-error">*</span> </label>
        <select id="PurposeOfLoan2 " name="PurposeOfLoan2" class="required" >
        <option value="">-Select-</option>
                <?php 
			          foreach($arr_loan_purpose as $purpose): 
                          if($purpose == $loan_purpose_reason):
								  echo '<option value="'.$purpose.'" selected="selected">'.$purpose.'</option>';
							  else:
								  echo '<option value="'.$purpose.'">'.$purpose.'</option>';
                                                          
                          endif;
                      endforeach; 
                       ?>
              </select>
    </div>
    <div class="span6">
        <label>No. of dependant under 18</label>
       <select name="NumberofDependant1" id="NumberofDependant1" class="ui-wizard-content valid">
                  <?php
                for($inc = 0; $inc < 6; $inc++):
                    if($inc == $applicant_numberof_dependent):
							echo '<option selected="selected" value="'.$inc.'">'.$inc.'</option>';
						else:
							echo '<option value="'.$inc.'">'.$inc.'</option>';
                    endif;
                endfor;
                ?>
              </select>
</div>
</div>
</fieldset>
           <fieldset class="step third-assets" id="assetLiability">

<h2 ><img src="../assets/css/images/bullet-form.png" />Employment</h2>
<div class="row-fluid">
    <div class="span6">
        <label>Employment Status <span class="text-error">*</span> </label>
        <select name="TypeOfEmployment2" id="TypeOfEmployment2" class="typeofEmployement required norm">
       <?php 
                foreach($arr_employment_type as $emp_type): 	
                    if($emp_type == $applicant_employment_type):
                        echo '<option value="'.$emp_type.'" selected="selected">'.$emp_type.'</option>';
                    else:
                        echo '<option value="'.$emp_type.'">'.$emp_type.'</option>';
                    endif;
                endforeach; 
                ?>
              </select>
    </div>
    <div class="span6 control-group ">
        <label>Job Title <span class="text-error">*</span> </label>
        <input  type="text" name="TitleInOccupation1" id="TitleInOccupation1 " class="required" value="<?php if(isset($applicant_employment_occupation)) echo $applicant_employment_occupation; ?>" >
    </div>
    </div>
    <div class="row-fluid">
    <div class="span6 control-group">
        <label>Employer Name <span class="text-error">*</span></label>
        <input type="text" name="BusinessName1" id="BusinessName1 " value="<?php if(isset($applicant_employer_name)) echo $applicant_employer_name; ?>" class="capitalize required" >
    </div>
    <div class="span6 control-group ">
        <label>H.R. Contact Number<span class="text-error">*</span> </label>
        <input  type="text" class="required" name="WorkPhone1" id="WorkPhone1 " value="<?php if(isset($applicant_employer_phone)) echo $applicant_employer_phone; ?>">
    </div>
</div>

<h2>Expenses</h2>
    <p class="text-error"><strong >"Full disclousure is vital to your loan application"</strong></p>
    <hr>
<div class="row-fluid">
    <div class="span6">
        <label >Loan repayments </label>
    	<?php 
		$arr_time_period['Weekly'] = 'Weekly';
		$arr_time_period['Monthly'] = 'Monthly';
		
		?>
        <input  type="text" name="Liabilities[LoanRepayment][payment]" id="PersonalLoanPayment" value="<?php if(isset($liabilities_loanrepayment_payment)) echo $liabilities_loanrepayment_payment; ?>" placeholder="$" onBlur="totalpaymentCalculation()" class="currency liabilities phly">
        <select id="LoanRepaymentPeriod" name="LoanRepaymentPeriod"  class="ui-wizard-content valid">
        <?php 
		foreach($arr_time_period as $period): 
				if($liabilities_loanrepayment_paymentperiod == $period):
		?>
        <option selected="selected" value="<?php echo $period;  ?>"><?php echo $period;  ?></option>
        <?php 	else: ?>
		<option value="<?php echo $period;  ?>"><?php echo $period;  ?></option>
		<?php 	endif;
		endforeach; ?>
        </select>
    </div>
    <div class="span6">
        <label >Credit Card repayment:</label>
    
        <input  type="text" name="Liabilities[CreditCard][payment]" id="CreditCardPayment" value="<?php if(isset($liabilities_creditcard_payment)) echo $liabilities_creditcard_payment; ?>"  placeholder="$" onBlur="totalpaymentCalculation()" class="currency liabilities phly" >
        <select id="CreditCardPaymentPeriod" name="CreditCardPaymentPeriod"  class="ui-wizard-content valid">
         <?php 
		foreach($arr_time_period as $period): 
				if($liabilities_creditcard_paymentperiod == $period):
		?>
        <option selected="selected" value="<?php echo $period;  ?>"><?php echo $period;  ?></option>
        <?php 	else: ?>
		<option value="<?php echo $period;  ?>"><?php echo $period;  ?></option>
		<?php 	endif;
		endforeach; ?>
        </select>
    </div>
</div>

<div class="row-fluid">
    <div class="span6">
        <label>Boarding/Renting Fee
        (Your Share) <span class="text-error">*</span>	</label>
    
        <input  type="text" name="Liabilities[BoardingRentingFee][payment]" id="BoardingRentingFee" value="<?php if(isset($liabilities_boardingrentingfee_payment)) echo $liabilities_boardingrentingfee_payment ?>" placeholder="$"  class="currency phly">
        <select id="BoardingRentingPeriod" name="BoardingRentingPeriod"  class="ui-wizard-content valid">
         <?php 
		foreach($arr_time_period as $period): 
				if($liabilities_boardingrentingfee_paymentperiod == $period):
		?>
        <option selected="selected" value="<?php echo $period;  ?>"><?php echo $period;  ?></option>
        <?php 	else: ?>
		<option value="<?php echo $period;  ?>"><?php echo $period;  ?></option>
		<?php 	endif;
		endforeach; ?>
        </select>
    </div>
    <div class="span6 control-group ">
        <label>Other Living Expense  <span class="text-error">*</span> <a href="#" data-toggle="tooltip" title="Excluding renting fee, boarding fee, and mortgage."><i class="fa fa-info-circle"></i>  </a> 	</label>
    
        <input type="text" name="Liabilities[LivingExpenses][payment]" id="LivingExpensesPayment " value="<?php if(isset($liabilities_livingexpenses_payment)) echo $liabilities_livingexpenses_payment; ?>" placeholder="$" class="currency required phly" >
        <select id="LivingExpensesPeriod" name="LivingExpensesPeriod"  class="ui-wizard-content valid">
         <?php 
		foreach($arr_time_period as $period): 
				if($liabilities_livingexpenses_paymentperiod == $period):
		?>
        <option selected="selected" value="<?php echo $period;  ?>"><?php echo $period;  ?></option>
        <?php 	else: ?>
		<option value="<?php echo $period;  ?>"><?php echo $period;  ?></option>
		<?php 	endif;
		endforeach; ?>
        </select>
    </div>
</div>

  </fieldset>
				<fieldset class="step fifth-credit" id="done">

<h2><img src="../assets/css/images/bullet-form.png" />Credit History</h2>
<div class="row-fluid">
    <div class="span5">
        <div class="form-horizontal">
            <div class="control-group">
                <label class="control-label">Have you ever applied for hardship? <span class="text-error">*</span></label>
                <div class="controls">
                    <input <?php if(isset($applicant_hardship) && $applicant_hardship == 'No') echo 'checked="checked"' ?> name="Hardship1" type="radio" value="No" id="Hardship1No" class="required HardshipNo" >   
                    Yes</label>
<input <?php if(isset($applicant_hardship)  && $applicant_hardship == 'Yes') echo 'checked="checked"' ?> name="Hardship1" type="radio" value="Yes" id="Hardship1Yes" class="HardshipYes" >
                    No</label> 
                </div>
            </div>
        </div>
    </div>

  <div class="span7"> 
    <div class="form-horizontal">
        <div class="control-group">
            <label class="control-label">Have you got a loan from anywhere in last 2 months? <span class="text-error">*</span></label>
                <div class="controls">
                     <input <?php if(isset($applicant_gambling) && $applicant_gambling == 'No') echo 'checked="checked"' ?> name="Gambling1" type="radio" value="No" id="Gambling1No" class="required GamblingNo"  >   
                    Yes
<input <?php if(isset($applicant_gambling)  && $applicant_gambling == 'Yes') echo 'checked="checked"' ?> name="Gambling1" type="radio" value="Yes" id="Gambling1Yes" class="GamblingYes" >
                    No
                </div>
        </div>
        
         <div class="control-group">
 <label class="control-label">Your credit history <span class="text-error">*</span></label>
            
            <?php 
			$arr_chistory[] = 'Clean (no default)'; 
			$arr_chistory[] = '1 default'; 
			$arr_chistory[] = '2 default'; 
			$arr_chistory[] = '3 or more default'; 
			$arr_chistory[] = 'Under bankruptcy'; 
			$arr_chistory[] = 'Ex-bankrupt'; 
			$arr_chistory[] = 'Under Part IX debt agreement'; 
			$arr_chistory[] = 'Past Part IX debt agreement';  
			?>
    <select name="CreditHistory2" id="CreditHistory2" class="chistory required norm controls">
    	<option value="" selected="selected">-Select-</option>
    	<?php foreach($arr_chistory as $chistory): ?>
    	<?php if(isset($applicant_credit_history) && $applicant_credit_history == $chistory): ?>
        <option value="<?php echo $chistory; ?>" selected="selected"><?php echo $chistory; ?></option>
        <?php else: ?>
        <option value="<?php echo $chistory; ?>"><?php echo $chistory; ?></option>
        <?php endif; ?>
        <?php endforeach; ?>

              </select>
             
    <div id="1defaulthtml1" class="defaulthtml">
       <input  type="text" class="capitalize currency minAmt controls" name="totalOutstanding2" id="totalOutstanding2" value="<?php if(isset($applicant_total_outstanding)) echo $applicant_total_outstanding; ?>" />
              <label class="control-label">Total outstanding value <span class="text-error">*</span></label><span class="fieldIcon"></span>
</div>
    
    <div class="xbankrupt">
   <label class="control-label">Date of discharge <span class="text-error">*</span></label><span class="fieldIcon"></span>
    <input type="text" class="required controls " id="DateOfDischarge1" name="DateOfDischarge1" value="<?php if(isset($applicant_date_discharge)) echo $applicant_date_discharge; ?>">
   
    <label class="control-label">Did you have any default/s after discharging from debt agreement/bankruptcy?* <span class="text-error">*</span></label><span class="fieldIcon"></span>  
   <input type="text" class="required controls" id="DefaultAfterDischarge1" name="DefaultAfterDischarge1" value="<?php if(isset($default_after_discharge)) echo $default_after_discharge; ?>" >
   
   
   <label class="control-label">Why did you choose Morgan Finance?</label> <span class="fieldIcon"></span>
       <input type="text" id="WhyChooseMF" name="WhyChooseMF" class="controls" value="<?php if(isset($why_choose_mc)) echo $why_choose_mc; ?>">
       
    
  <label  class="control-label"  for="ExistingClient">Have you taken out a loan with us before? <span class="text-error">*</span> 
  				</label><span class="fieldIcon"></span>     
  <input <?php if(isset($ExistingClient) || $ExistingClient == 'No') echo 'checked="checked"' ?> name="ExistingClient" type="radio" value="No" id="ExistingClient_no" class="controls"  >   
                    Yes
<input <?php if(isset($ExistingClient)  && $ExistingClient == 'Yes') echo 'checked="checked"' ?> name="ExistingClient" type="radio" value="Yes" id="ExistingClient_yes" class="required" controls >
                    No            
         <a href="#" data-toggle="tooltip" title="If a loan has not be taken out before, click No."><i class="fa fa-info-circle"></i>  </a>        
     </div>     
    </div> 
  </div>
</div> 
</div>
<div class="row-fluid">
    <p class="text-info"><a href="">Privacy Protection Policy </a> </p>
    <p>I/we acknowledge that I/we have provided truthful, correct and accurate information on this application form. We are informed that use of counterfeit document(s) and/or false information to obtain credit is a criminal offence.
    </p>
    <label>
    <input type="checkbox" id="AgreePrivacyCredit" name="AgreePrivacyCredit" class="required" value="AgreePrivacyCredit"> I/we have read and agreed to the privacy and credit information before 
    applying for this loan.
    </label> 
    </div>
    </fieldset>
    <div class="row-fluid">

  <input id="back" value="Back" type="reset" class="btn btn-green  btn-large span2 pull-right" />
       <input class="btn btn-green  btn-large span2 pull-right" id="next" value="Next" type="submit" onClick="$('#preapppass, #preappfail, #disclaimer, #bankrupt,#spec').hide();" /> 
 </div>
         <a href="#" id="disableWizard">Show All Pages</a> 
          <a href="#" id="showBUI" style="color:#f5f5f5; cursor:default">Show</a>
       </form>
   </div>
    <script type="text/javascript">
$('#preapppass, #preappfail, #bankrupt, #spec').hide();
$('.page1title').show();
if(name!=null && name!=""){
	
	if(status=='pass'){
		$('.page1title').hide();
		$('#preappfail').hide();
		$('#preapppass, #spec').show();
	}
	if(status=='fail'){
		$('.page1title').hide();
		$('#preapppass').hide();
		$('#bankrupt').hide();
		if(chistory=="Under bankruptcy" || chistory=="Under Part IX debt agreement")
			$('#bankrupt').show();
		else 
			$('#preappfail').show();
	}
}
else{
	$('#preapppass, #preappfail, #spec').hide();
	
}

$('#submitNotice').hide();

	$('#hiddendiv').dialog('open');
	$('#contButtons').show();

		
        var choice = '<?php if(isset($applicant_credit_history)) echo $applicant_credit_history; ?>'; 		
        var Id = 'CreditHistory1';
        var j = Id.substr(Id.length - 1);
		
        if (choice == '1 default' || choice == '2 defaults' || choice == '3 or more defaults') {

            $('#1defaulthtml' + j).show('1000').find(':input,textarea,select').removeAttr('disabled');

            if (choice == '2 defaults' || choice == '3 or more defaults') {

                $('#2defaulthtml' + j).show('1000').find(':input,textarea,select').removeAttr('disabled');

            }
            else {

                $('#2defaulthtml' + j).hide('1000').find(':input,textarea,select').removeClass('error').attr('disabled', 'disabled');
            }

        }
        else {

            $('#1defaulthtml' + j).hide('1000').find(':input,textarea,select').removeClass('error').attr('disabled', 'disabled');
            $('#2defaulthtml' + j).hide('1000').find(':input,textarea,select').removeClass('error').attr('disabled', 'disabled');
            $('#more').remove();
        }

        if (choice == 'Ex-bankrupt' || choice == 'Past Part IX debt agreement') {
            $('.xbankrupt').fadeIn('1000').find(':input,textarea,select').removeAttr("disabled");

        }
        else {
            $('.xbankrupt').fadeOut('1000').find(":input,textarea,select").removeClass('error').attr('disabled', 'disabled');
        }

</script>  